﻿#pragma once
#include"BRTree.h"



namespace zhz
{

	template<class K>
	class set
	{
		struct SetkeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};


	public:
		//使用typename避免编译器将Iterator识别为静态成员变量
		typedef typename RBTree<K, const K, SetkeyOfT>::Iterator iterator;
		typedef typename RBTree<K, const K, SetkeyOfT>::constIterator const_iterator;

		pair<iterator, bool> insert(const K& key)
		{
			return _rbtree.Insert(key);
		}

		iterator begin()
		{
			return _rbtree.Begin();
		}
		iterator end()
		{
			return _rbtree.End();
		}
		const_iterator begin()const
		{
			return _rbtree.Begin();
		}
		const_iterator end()const
		{
			return _rbtree.End();
		}

		iterator find(const K& key)
		{
			return _rbtree.Find(key);
		}



	private:
		RBTree<K, const K, SetkeyOfT> _rbtree;


	};

	void Print(const set<int>& s)
	{
		set<int>::const_iterator it = s.end();
		while (it != s.begin())
		{
			--it;
			// ֧޸
			//*it += 2;
			cout << *it << " ";
		}
		cout << endl;
	}

	void test_set()
	{

		set<int> s;
		/*s.insert(1);
		s.insert(4);
		s.insert(2);
		s.insert(3);*/

		int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
		for (auto x : a)
			s.insert(x);

		Print(s);
		set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;



	}




}